﻿Public Class ucNatureza


    Public Property getIdTipoPericia() As Integer

        Get
            Return cmbTipoPericia.SelectedValue

        End Get

        Set(ByVal value As Integer)

            cmbTipoPericia.SelectedValue = value

        End Set

    End Property


    Public Property getIdNatureza() As Integer

        Get
            Return cmbNatureza.SelectedValue

        End Get

        Set(ByVal value As Integer)

            cmbNatureza.SelectedValue = value

        End Set

    End Property

    Public Property getDescNaturezaPericia() As String

        Get
            Return CType(cmbNatureza.SelectedItem, naturezaVO).DENOMINACAO_OFICIAL

        End Get

        Set(ByVal value As String)


        End Set

    End Property


    Private Sub ucNatureza_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        populaDados()

    End Sub


    Private Sub populaDados()

        Try
            If Not DesignMode Then

                cmbNatureza.Enabled = False

                Dim tipoPericia As New tipo_periciaBO
                Dim lista As New Generic.List(Of tipo_periciaVO)
                lista = tipoPericia.getTipoPericias()

                If lista.Count = 0 Then

                    cmbTipoPericia.DataSource = Nothing
                    cmbTipoPericia.Items.Insert(0, "Não há naturezas cadastradas para esta seção")
                    cmbTipoPericia.SelectedIndex = 0

                Else


                    cmbTipoPericia.DisplayMember = "DESC_TIPO"
                    cmbTipoPericia.ValueMember = "ID_TIPO"
                    cmbTipoPericia.DataSource = lista
                    cmbNatureza.Enabled = False


                End If
            End If

        Catch ex As Exception

            generica.gravaErro(ex)

        End Try
    End Sub

    Private Sub cmbTipoPericia_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cmbTipoPericia.KeyPress
        e.Handled = True
    End Sub

    Private Sub cmbTipoPericia_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbTipoPericia.SelectedIndexChanged

        If cmbTipoPericia.SelectedValue > 0 Then
            populaNatureza(cmbTipoPericia.SelectedValue)
        Else

            limpaCombo()
        End If
    End Sub

    Private Sub limpaCombo()

        Try

            cmbNatureza.Enabled = False
            cmbNatureza.DataSource = Nothing
            cmbNatureza.Items.Clear()
            cmbNatureza.SelectedIndex = -1
        Catch ex As Exception

            generica.gravaErro(ex)

        End Try



    End Sub


    Private Sub populaNatureza(ByVal tipoPericia As Integer)

        Try


            If Not DesignMode Then

                Dim natureza As New naturezaBO
                Dim lista As Generic.List(Of naturezaVO)
                lista = natureza.getTipoNatureza(tipoPericia)

                If lista.Count = 0 Then

                    cmbNatureza.DataSource = Nothing
                    cmbNatureza.Items.Insert(0, "Não existem tipos de perícia cadastradas para a natureza selecionada")
                    cmbNatureza.SelectedIndex = 0
                    cmbNatureza.Enabled = False

                Else

                    cmbNatureza.Enabled = True
                    cmbNatureza.DisplayMember = "DESC_NATUREZA"
                    cmbNatureza.ValueMember = "ID_NATUREZA"
                    cmbNatureza.DataSource = lista


                End If

            End If

        Catch ex As Exception

            generica.gravaErro(ex)


        End Try


    End Sub

    Private Sub cmbNatureza_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cmbNatureza.KeyPress
        e.Handled = True
    End Sub

  
    Public Event cmbTipoPericiaSelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Private Sub cmbTipoPericia_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbTipoPericia.SelectionChangeCommitted
        RaiseEvent cmbTipoPericiaSelectionChangeCommitted(sender, e)
    End Sub
End Class


